package com.sq.loginservice.service.impl;

import com.sq.api.dto.SysLoginLogDto;
import com.sq.api.log.LogServiceApi;
import com.sq.common.constants.Constants;
import com.sq.common.utils.request.RequestUtil;
import com.sq.common.web.R;
import com.sq.loginservice.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @Author Li sir
 * @Date 2024/9/30
 */

@Service
public class LoginLogServiceImpl implements LogService {

    @Autowired
    private LogServiceApi logServiceApi;

    @Override
    public void saveLog(SysLoginLogDto loginLogDto) {

    }


    @Override
    public int saveLog(String userName, String status, String msg) {
        SysLoginLogDto sysLoginLogDto = new SysLoginLogDto();
        sysLoginLogDto.setLoginTime(new Date());
        sysLoginLogDto.setUserName(userName);
        if (Constants.LOGIN_SUCCESS.equals(status)){
            sysLoginLogDto.setStatus(Constants.LOGIN_SUCCESS_STATUS);
        }else {
            sysLoginLogDto.setStatus(Constants.LOGIN_FAIL_STATUS);
        }
        sysLoginLogDto.setMsg(msg);
        sysLoginLogDto.setOs(RequestUtil.getUserOsName());
        sysLoginLogDto.setBrowser(RequestUtil.getBrowserVersion());
        sysLoginLogDto.setIpaddr(RequestUtil.getRequestIp());
        Map<String, String[]> requestParam = RequestUtil.getRequestParam();
        R r = logServiceApi.saveLoginLog(sysLoginLogDto);
        return 0;
    }
}
